package com.flash.BusinessData.controller;

import com.flash.BusinessData.entity.DealData;
import com.flash.BusinessData.entity.MarketData;
import com.flash.BusinessData.service.DealDataService;
import com.flash.BusinessParameters.entity.BondSetting;
import com.flash.GlobalManagement.util.Dbutil;
import com.flash.GlobalManagement.util.TableIdUtil;
import com.flash.GlobalManagement.util.TableNameUtil;
import com.flash.GlobalManagement.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static oracle.security.pki.util.SignatureAlgorithms.i;

@Controller
public class DealDataController {
    @Resource
    DealDataService dealDataService;

    @Resource
    Dbutil dbutil;

    /**
     * 按条件查询
     * @param dealData
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/selectDealDataMap2")
    @ResponseBody
    public Map selectDealDataMap(DealData dealData,int page,int limit){
        System.out.println("测试交易数据");
        HashMap map = new HashMap();
        List<DealData> dealDataList = dealDataService.selectDealDataMap(dealData, page, limit);
        int i = dealDataService.selectCountDealData();
        System.out.println(dealDataList);
        map.put("code",0);
        map.put("msg","");
        map.put("data",dealDataList);
        map.put("count",i);
        return map;
    }

    /**
     * 增加
     * @param dealData
     * @return
     */
    @RequestMapping("InsertDealData")
    @ResponseBody
    public String InsertDealData(DealData dealData){
        System.out.println("我是增加的Controller");
        dealData.setDealId(dbutil.getMaxId3(TableIdUtil.DDID,TableNameUtil.DD, TableTimeUtil.DDTime,dealData.getDealTime()));
        System.out.println(dealData);
        int i = dealDataService.insertDealData(dealData);
        System.out.println(i+"aaaaaaaaaaaaaaaaaaaaaaaaaa");
        if (i>0){
            return "ok";
        }else{
            return "no";
        }
    }


    /**
     * 删除
     * @param dealId
     * @return
     */
    @RequestMapping("/deleteDealData")
    @ResponseBody
    public int deleteDealData(String dealId){
        System.out.println("删除");
        int i = dealDataService.deleteDealData(dealId);
        System.out.println(i);
        return i;
    }

    /**
     * 修改
     * @param dealData
     * @return
     */
    @RequestMapping("/updateDeaData")
    @ResponseBody
    public int updateDeaData(DealData dealData){
        System.out.println("修改");
        int i = dealDataService.updateDeaData(dealData);
        System.out.println(i);
        return i;
    }

}
